package com.example.administrator.xiaobo.adapter.show_adapter;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ToxicBakery.viewpager.transforms.CubeInTransformer;
import com.ToxicBakery.viewpager.transforms.CubeOutTransformer;
import com.ToxicBakery.viewpager.transforms.DepthPageTransformer;
import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.example.administrator.xiaobo.R;
import com.example.administrator.xiaobo.bean.show_5_itemBean;
import com.example.administrator.xiaobo.holder.MyConvenientBarHolder;
import com.example.administrator.xiaobo.utils.ListRandomHelper;

import java.util.LinkedList;

import static com.bumptech.glide.gifdecoder.GifHeaderParser.TAG;

/**
 * Created by Administrator on 2017/2/9.
 * viewType = 5
 */

public class ShowAdapter5 extends RecyclerView.Adapter<ShowAdapter5.MyViewHolder> {
    private Context context;
    private LinkedList<show_5_itemBean> data;
//    private ConvenientBanner convenientBanner;
    public ShowAdapter5(Context context, LinkedList<show_5_itemBean> data) {
        this.context = context;
        this.data = data;
    }
    private Handler handler;

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_show_0203,null);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        LinkedList<show_5_itemBean> text = new LinkedList<>();
        for (show_5_itemBean show_5_itemBean : data) {
            text.add(show_5_itemBean);
        }
        Log.e(TAG, "onBindViewHolder: "+data.size() );
        LinkedList linkedList = ListRandomHelper.randomList(text);
        Log.e(TAG, "onBindViewHolder: "+linkedList.size());
        Log.e(TAG, "onBindViewHolder: "+data.size());
        holder.convenientBanner.setPages(new CBViewHolderCreator() {
            @Override
            public Object createHolder() {
                return new MyConvenientBarHolder();
            }
        },linkedList);
        Log.e(TAG, "onBindViewHolder: "+position );
//        holder.convenientBanner.setPageTransformer(new RotateUpTransformer());
        handler = new Handler(){
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                if (msg.what == 0x110) {
                    holder.convenientBanner.startTurning(7000);
                }
                else if(msg.what == 0x120){
                    holder.convenientBanner.startTurning(6000);
                }else
                holder.convenientBanner.startTurning(5000);
            }
        };
        if (position ==0) {
            holder.convenientBanner.setPageTransformer(new CubeInTransformer());
            holder.convenientBanner.setScrollDuration(2000);
            handler.sendEmptyMessageDelayed(0x110,5000);
        }else if(position ==1){
            holder.convenientBanner.setPageTransformer(new CubeOutTransformer());
            holder.convenientBanner.setScrollDuration(2000);
            handler.sendEmptyMessageDelayed(0x120,3000);

        }else if (position == 2){
            holder.convenientBanner.setPageTransformer(new DepthPageTransformer());
            holder.convenientBanner.setScrollDuration(2000);
            handler.sendEmptyMessageDelayed(0x130,1000);
        }
//        holder.convenientBanner.startTurning(1500);
    }

    @Override
    public int getItemCount() {
        return 3;
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        ConvenientBanner convenientBanner;
        public MyViewHolder(View itemView) {
            super(itemView);
            convenientBanner = (ConvenientBanner) itemView.findViewById(R.id.convenientBanner);
        }
    }
}
